﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using RonYee.Models;
using RonYee.Service;

namespace RonYee.Controllers
{
    public class HomeController : Controller
    {
        RongeDb db = new RongeDb();

        [Authorize]
        public ActionResult Zone()
        {
            return View();
        }

        [Authorize(Roles = "Admin,Editer")]
        public ActionResult Manage()
        {
            return View();
        }
        
        public ActionResult Index()
        {
            var news = (from n in db.Newss
                       orderby n.AddTime descending
                       where n.NewsType1==1
                       select n).Take(8);
            ViewData["baseNews"] = news;

            var file = (from f in db.Files
                       orderby f.AddTime descending
                       select f).Take(8);
            ViewData["baseFile"] = file;

            var imgnews = (from i in db.ImgNewss
                           orderby i.AddTime descending
                           select i).Take(5);
            ViewData["baseImgnews"] = imgnews;

            return View();

        }
        public ActionResult About()
        {
            var n1 = (from n in db.Newss
                      where n.NewsType1 == 2
                      orderby n.AddTime
                      select n).Take(1);

            var news = from n in db.Newss
                       orderby n.AddTime descending
                       where n.NewsType1 == 2
                       select n;
            ViewData["about"] = n1;
            ViewData["aboutNews"] = news;

            return View();
        }

        public ActionResult AboutRonge(int id) 
        {
            var n1 = from n in db.Newss
                     where n.NewsId == id
                     select n;

            var news = from n in db.Newss
                       orderby n.AddTime descending
                       where n.NewsType1 == 2
                       select n;
            ViewData["about"] = n1;
            ViewData["aboutNews"] = news;

            return View();
        }

        public ActionResult Notice() 
        {
            var news = (from n in db.Newss
                        orderby n.AddTime descending
                        where n.NewsType1 == 1
                        select n).Take(20);
            ViewData["NewsList"] = news;

            var file = (from f in db.Files
                        orderby f.AddTime descending
                        select f).Take(8);
            ViewData["FileList"] = file;

            return View();
        }

        [HttpPost,HttpGet]
        public ActionResult Search(Book bookSearch)
        {
            return View();
        }

    }
}
